
# -*- coding: utf-8 -*-

import random
import os
import addRandomUI
import PathConfig


  

def cleanEvent(file_path):
	file_data = ""
	print('filePath------'+file_path)
	Ropen = open(file_path,'r')
	flagCount = 0
	for line in Ropen:

		if (PathConfig.filter_rub not in line) and (PathConfig.prefix_rub not in line):
			file_data += line
    	
	Ropen.close()
	Wopen=open(file_path,'w')
	Wopen.write(file_data)
	Wopen.close()


def removeCode(file_path):
    
	if '.h' in file_path:  # file_dir+'/'+file含义是file_dir文件夹下的file文件
		# 获取文件中 @end 的总数量，在最后一个 @end 前面添加垃圾代码
		if ("+" not in file_path):
			cleanEvent(file_path)
				
	if '.m' in file_path:
		cleanEvent(file_path)
			
        

# 循环递归遍历文件夹
def traverse(file_dir):
	fs = os.listdir(file_dir)
	for dir in fs:
		tmp_path = os.path.join(file_dir, dir)
		if not os.path.isdir(tmp_path):
			removeCode(tmp_path)
		else:
			# 是文件夹,则递归调用
			traverse(tmp_path)


def removeRubbish():
    
	traverse(PathConfig.rub_filepath)


def main():
	removeRubbish()
	print('Finish done')


if __name__ == '__main__':
	main()